<?php
require_once 'vendor/autoload.php';

use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule;
$capsule->addConnection([
    'driver'    => 'mysql',
    'host'      => '129.226.194.102',
    'database'  => 'aimeos_lvgang_to',
    'username'  => 'aimeos_lvgang_to',
    'password'  => 'ZQaJw6X9nksn8kt7',
    'charset'   => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'prefix'    => '',
]);

$capsule->setAsGlobal();
$capsule->bootEloquent();

try {
    $pdo = $capsule->getConnection()->getPdo();
    
    // Create mshop_locale table
    $sql = "CREATE TABLE IF NOT EXISTS mshop_locale (
        id INT AUTO_INCREMENT PRIMARY KEY,
        siteid VARCHAR(255) NOT NULL DEFAULT 'default',
        langid VARCHAR(5) NOT NULL DEFAULT 'en',
        currencyid VARCHAR(3) NOT NULL DEFAULT 'USD',
        pos SMALLINT NOT NULL DEFAULT 0,
        status SMALLINT NOT NULL DEFAULT 1,
        mtime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
        ctime DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
        editor VARCHAR(255) NOT NULL DEFAULT '',
        UNIQUE KEY unq_mslocale_sid_lang_curr (siteid, langid, currencyid),
        KEY idx_mslocale_status (status),
        KEY idx_mslocale_pos (pos)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
    
    $pdo->exec($sql);
    echo "mshop_locale table created successfully\n";
    
    // Insert default locale data
    $insertSql = "INSERT IGNORE INTO mshop_locale (siteid, langid, currencyid, pos, status, editor) VALUES 
        ('default', 'en', 'USD', 0, 1, 'setup'),
        ('default', 'zh', 'CNY', 1, 1, 'setup');";
    
    $pdo->exec($insertSql);
    echo "Default locale data inserted successfully\n";
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}